// 路由规则的模块
import { constantRoutes, asyncRoutes } from '@/router' // 静态路由规则
const state = {
  routes: constantRoutes
}
const mutations = {
  // 新增路由规则
  setRoutes(state, filterRoutes) {
    state.routes = [...constantRoutes, ...filterRoutes, { path: '*', redirect: '/404', hidden: true }]
  }
  // 重置路由规则
  /*  resetRoutes(state) {
    state.routes = constantRoutes
  } */
}
const actions = {
  // action中所有的函数默认返回值是promise
  filterRoutes({ commit }, menus) {
    const filterRoutes = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    // 提交mutation设置动态路由
    commit('setRoutes', filterRoutes) // 到此只是完成了vuex数据的处理
    return filterRoutes // 必须返回 供addRoutes新增规则用
  },
  fn() {
    return 100
  }
}
export default {
  // 开启命名空间
  namespaced: true,
  state,
  mutations,
  actions
}
